﻿using System;
using System.Threading.Tasks;
using Magicodes.WeChat.SDK;
using Magicodes.WeChat.SDK.Apis.TemplateMessage;

namespace Magicodes.WeChat.Application.TemplateMessage
{
    public class WeChatTemplateMessageAppService : IWeChatTemplateMessageAppService
    {
        /// <summary>
        /// 添加模板
        /// </summary>
        /// <param name="shortId"></param>
        /// <returns></returns>
        public Task<TemplateMessageAddTemplateAPIResult> AddTemplate(string shortId)
        {
            return Task.FromResult(WeChatApisContext.Current.TemplateMessageApi.AddTemplate(shortId)
                .HanderApiResultError());
        }

        /// <summary>
        /// 获取所有模板
        /// </summary>
        /// <returns></returns>
        public Task<TemplateMessageGetAPIResult> GetAll()
        {
            return Task.FromResult(WeChatApisContext.Current.TemplateMessageApi.Get().HanderApiResultError());
        }

        /// <summary>
        /// 移除模板
        /// </summary>
        /// <param name="templatId"></param>
        /// <returns></returns>
        public Task Remove(string templatId)
        {
            WeChatApisContext.Current.TemplateMessageApi.Delete(templatId).HanderApiResultError();
            return Task.FromResult(0);
        }

        /// <summary>
        /// 发送
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Task<Guid> Send(TemplateMessageCreateModel model)
        {
            return Task.FromResult(WeChatApisContext.Current.TemplateMessageApi.Create(model));
        }
    }
}